package com.um.jdy.ykc.command;

import com.um.jdy.ykc.utils.RadixsUtil;
import lombok.Data;

/**
 * 充电握手（充电桩->运营平台）
 *
 * @author 甘天伟
 * @since 2022/6/28
 * 版权所有 广州优匠科技有限公司
 */
@Data
public class Cmd15ChargeHandshake extends YkcCommand {

    /**
     * 交易流水号：16个字节
     */
    private String transactionNo;

    /**
     * 桩编码：7个字节
     */
    private String code;

    /**
     * 枪号：1个字节
     */
    private int gunNo;

    /**
     * BMS 通信协议版本号：3个字节
     */
    private int bmsProtocolVersion;

    /**
     * BMS 电池类型：1个字节
     */
    private int bmsBatteryType;

    /**
     * BMS 整车动力蓄电池系统额定容量：2个字节
     */
    private int bmsBatteryCapacity;

    /**
     * BMS 整车动力蓄电池系统额定总电压：2个字节
     */
    private int bmsBatteryVoltage;

    /**
     * BMS 电池生产厂商名称：4个字节
     */
    private String bmsBatteryVendor;

    /**
     * BMS 电池组序号：4个字节
     */
    private int bmsBatterySerial;

    /**
     * BMS 电池组生产日期年：1个字节
     */
    private int bmsBatteryProductionYear;

    /**
     * BMS 电池组生产日期月：1个字节
     */
    private int bmsBatteryProductionMonth;

    /**
     * BMS 电池组生产日期日：1个字节
     */
    private int bmsBatteryProductionDay;

    /**
     * BMS 电池组充电次数：3个字节
     */
    private int bmsBatteryChargeCount;

    /**
     * BMS 电池组产权标识：1个字节
     */
    private int bmsBatteryPropertyRight;

    /**
     * 预留位: 1个字节
     */
    private int reserved;

    /**
     * BMS 车辆识别码：17个字节
     */
    private String bmsCarVin;

    /**
     * BMS 软件版本号：8个字节
     */
    private long bmsSoftwareVersion;

    @Override
    public void parseBytes(byte[] bytes) {
        super.parseBytes(bytes);
        transactionNo = RadixsUtil.bytesToHexString(readBytes(data, 0, 16));
        code = RadixsUtil.bytesToHexString(readBytes(data, 16, 7));
        gunNo = RadixsUtil.byteToInteger(data[23]);
        bmsProtocolVersion = RadixsUtil.bytesToInteger(readBytes(data, 24, 3));
        bmsBatteryType = RadixsUtil.byteToInteger(data[27]);
        bmsBatteryCapacity = RadixsUtil.bytesToInteger(readBytes(data, 28, 2));
        bmsBatteryVoltage = RadixsUtil.bytesToInteger(readBytes(data, 30, 2));
        bmsBatteryVendor = RadixsUtil.bytesToString(readBytes(data, 32, 4));
        bmsBatterySerial = RadixsUtil.bytesToInteger(readBytes(data, 36, 4));
        bmsBatteryProductionYear = RadixsUtil.byteToInteger(data[40]) + 1985;
        bmsBatteryProductionMonth = RadixsUtil.byteToInteger(data[41]);
        bmsBatteryProductionDay = RadixsUtil.byteToInteger(data[42]);
        bmsBatteryChargeCount = RadixsUtil.bytesToInteger(readBytes(data, 43, 3));
        bmsBatteryPropertyRight = RadixsUtil.byteToInteger(data[46]);
        reserved = RadixsUtil.byteToInteger(data[47]);
        bmsCarVin = RadixsUtil.bytesToAscii(readBytes(data, 48, 17)).trim();
        bmsSoftwareVersion = RadixsUtil.bytesToLong(readBytes(data, 65, 8));

        transactionNo = RadixsUtil.getTransactionNo(transactionNo);
        code = RadixsUtil.getCode(code);
    }
}
